  (async function(){
  const fs = require("fs");
  const path = require("path");
  const info = require("debug")('log:info');

  const config = require("./config.js")[process.env.RUN_CONF];

  const db = require("./mysql.js");
  async function userList(){
    let sql =`select a.id, a.buyHouseNum,a.img_buyhouse imgBuyhouse,a.img_daikuan imgDaikuan,
    a.name1,a.img_idfront1 imgIdfront1,a.img_idback1 imgIdback1,
    a.name2,a.img_idfront2 imgIdfront2,a.img_idback2 imgIdback2,
    a.name3,a.img_idfront3 imgIdfront3,a.img_idback3 imgIdback3
     from bxa_user_${config.tt} a`;
    return await db.query(sql+" order by a.id");
  }
  const downList = await userList();
  const dirName = 'download';
  downList.forEach(o=>{
    if(fs.existsSync(`./${dirName}/${o.buyHouseNum}`)){
        fs.rename(`./${dirName}/${o.buyHouseNum}`,`./${dirName}/${o.id}`,()=>{
            info(`${o.buyHouseNum} rename as ${o.id}`);
        });
    }
  });
})()
